package student.productions;

import java.util.List;

/**
 * Node that can directly mutate itself
 */
public abstract class MutableNode extends AbstractNode {
	//Invariant for children: Every Node in children is a subtype of MutableNode.
	
	/**
	 * Randomly applies one of the mutations that are possible for this node
	 * @param genome the Program containing this node
	 * Effects: directly mutates this node
	 */
	public abstract void mutate(Program genome);
	
	/**
	 * Adds this node and all of this node's children to toAppend
	 * @param toAppend the list to add all the nodes to
	 */
	public void addMutableTree(List<MutableNode> toAppend){
		toAppend.add(this);
		for(AbstractNode n : children){
			((MutableNode)n).addMutableTree(toAppend);
		}
	}
}
